package com.ruoyi.receipt.instener;

import java.math.BigDecimal;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;
import org.springframework.stereotype.Component;

import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.Product;
import com.ruoyi.system.domain.ReceiptForm;
import com.ruoyi.system.service.IProductService;
import com.ruoyi.system.service.IReceiptFormService;


@Component
public class ReceiptFormEndStateListener implements ExecutionListener {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Expression state;
    private static String FIX_FEE = "3"; // 维修费
    @Override
    public void notify(DelegateExecution delegateExecution) {
        IReceiptFormService receiptFormService = (IReceiptFormService) SpringUtils.getBean(IReceiptFormService.class);
        IProductService productService = (IProductService) SpringUtils.getBean(IProductService.class);

        long id = Long.parseLong(delegateExecution.getProcessInstanceBusinessKey());
        ReceiptForm rf = receiptFormService.selectReceiptFormById(id);
        rf.setContactMobile("17792056618");
        rf.setStatus("DONE");

        // 只有维修费不需要进入备品表
       /* if (!FIX_FEE.equals(rf.getExpectUseOpt())) {
            Product p = new Product();

            p.setDeptId(1L);
            if (!rf.getUnitPrice().isEmpty()) {
                p.setPrice(new BigDecimal(rf.getUnitPrice().replaceAll(",", "")));
            }
            if (!rf.getTotalPrice().isEmpty()) {
                p.setTotalPrice(new BigDecimal(rf.getTotalPrice().replaceAll(",", "")));
            }
            p.setBoughtAt(rf.getPurchaseDate());
            p.setProductName(rf.getAssetName());
            p.setProductNo(rf.getVoucherNo());
            p.setProductModel(rf.getModel());
            p.setNumber(Long.parseLong(rf.getQuantity()));
            p.setProductSpec(rf.getSpecs());
           // p.setProjectId(1L);
            p.setCreateBy(rf.getCreateBy());
            p.setUseFor(rf.getExpectUseOpt());
            productService.insertProduct(p);
        }*/
        receiptFormService.updateReceiptForm(rf);
    }
}
